package com.baizhi.controller;

import com.baizhi.entity.BzMenu;
import com.baizhi.service.IBzMenuService;
import com.baizhi.vo.ZtreeNodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("menu")
public class BzMenuController {
    @Autowired
    private IBzMenuService menuService;

    /**
     * 控制只有用户具有 ADMIN 的角色才能查询菜单数据
     */
    @PreAuthorize("@ss.hasRole('vip')")
    @GetMapping("selectMenuListBySql")
    public List<BzMenu> selectMenuListBySql() {
        return menuService.selectMenuListBySql();
    }

    /**
     * 控制只有用户具有 sys:ztree:select 的权限才能查询菜单数据
     */
    @PreAuthorize("@ss.hasPermission('sys:ztree:select')")
    @GetMapping("getZtreeNodes")
    public List<ZtreeNodeVo> getZtreeNodes() {
        return menuService.selectZtreeNodesBySql();
    }
}
